#ifndef __PERIPHERAL_H__
#define __PERIPHERAL_H__

#include "user_define.h"


//#define RELAY_PORT              GPIOD
//#define RELAY_PIN               GPIO_PIN_12
//#define RELAY_ON                RELAY_PORT->BIT_SET_RST = RELAY_PIN
//#define RELAY_OFF               RELAY_PORT->BIT_RST = RELAY_PIN

//#define BEEP_PORT               GPIOD
//#define BEEP_PIN                GPIO_PIN_12

#define WIRELESS_PORT           GPIOA
#define WIRELESS_PIN            GPIO_PIN_4
#define WIRELESS_IRQn           GPIOA_IRQn
#define WIRELESS_IRQHandler     GPIOA_IRQHandler

#define AC_PORT           GPIOD
#define AC_PIN            GPIO_PIN_13
#define AC_IRQn           GPIOD_IRQn

//#define BEEP_ON                 BEEP_PORT->BIT_SET_RST = BEEP_PIN
//#define BEEP_OFF                BEEP_PORT->BIT_RST = BEEP_PIN

#define WIRELESS_REC_BIT_BUF_LEN       33  //20bit地址+5bit命令+3bit序号+4bit效验码+1bit结束码

#define WIRELESS_BIT0_TIM              24000  //500US


#define BEEP_ON_TIME                   2  //单位ms

#define ON_OFF_TIME_MAX                14400 //=2*60*60*2 单位500ms

#define FLASH_OPERATE_ADDR   (DPM_FLASH_BASE + 127*DPM_PAGE_SIZE)

typedef struct
{
    uint8_t RecComplete;    //接收完成
    uint8_t RecError;       //错误标志
		uint8_t FirstLong;
		uint8_t KeyLong;
    uint8_t RecBitCnt;      //接收的数据长度
    uint8_t RecNum;         //接收到的命令序号
    uint8_t RecBitBuf[WIRELESS_REC_BIT_BUF_LEN];  //接收数据缓存
}WIRELESS_REC;
extern WIRELESS_REC WrilessRec;

typedef struct
{
    uint32_t addr;
    uint8_t  cmd;
    uint8_t  num;
    uint8_t  crc;
    uint8_t  numLast;
}WIRELESS_DAT;


typedef struct
{
    uint8_t status;
    uint16_t cnt;
}BEEP;

typedef struct
{
    uint8_t status;
    uint32_t timeCnt;
    uint32_t timeEnd;
}ON_OFF_TIME;

typedef struct
{
	  uint8_t CCT_Inc;
	  uint8_t CCT_Dec;
	  uint8_t Brightless_Inc;
	  uint8_t Brightless_Dec;
		uint8_t Start;
		//uint8_t ONOFF;
		uint8_t LedON;
		uint8_t FanON;
    int16_t Ydata;
    int16_t Wdata;
		int16_t YdataK;
    int16_t WdataK;
		int16_t startY;
		int16_t startW;
	  int16_t Brightless;
		uint16_t Cnt;
	
}LEDPWM;

extern LEDPWM PWMDuty;
	
extern BEEP Beep;
extern ON_OFF_TIME OnOffTime;
extern uint8_t FAN_Shake;
//extern uint16_t FAN_Cmd;
extern uint8_t FlagAC;
extern uint8_t FlagACOn;
extern uint16_t LEDCnt;

void Peripheral_Init(void);
void WrilessRec_Handler(void);
void LED_PWM(void);
void PWM_INCR(void);
void FlashRead(void);
void KeyScan(void);
void SleepMcu(void);
void LED_ACONOFF(void);
void LEDIncrDecr(void);
void LED_OFF(void);
//void beeon_pwm(uint16_t beenon_perid);

extern void SWO_reuseGPIO(void);

#endif

